package com.jy.appmarket.screenlock.utils;

import java.util.Calendar;

/**
 * 类说明：
 * 
 * @author kalui.huang
 * @date 2015-3-3
 * @version 1.0
 */
public class DateUtils {
	public static boolean isToday(long time) {
		Calendar calendar = Calendar.getInstance();
		int currentYear = calendar.get(Calendar.YEAR);
		int currentMouth = calendar.get(Calendar.MONTH);
		int currentDay = calendar.get(Calendar.DAY_OF_MONTH);

		calendar.setTimeInMillis(time);
		int storedYear = calendar.get(Calendar.YEAR);
		int storedMouth = calendar.get(Calendar.MONTH);
		int storedDay = calendar.get(Calendar.DAY_OF_MONTH);
		if (currentYear == storedYear) {
			if (currentMouth == storedMouth) {
                return currentDay == storedDay;
			}
		}
		return false;
	}

	public static boolean isFilterHours(int[] filters) {
		Calendar calendar = Calendar.getInstance();
		int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
		for (int filter : filters) {
			if (filter == currentHour) {
				return true;
			}
		}
		return false;
	}

	public static boolean isSameDay(long tm1, long tm2) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(tm1);
		int y1 = calendar.get(Calendar.YEAR);
		int m1 = calendar.get(Calendar.MONTH);
		int d1 = calendar.get(Calendar.DAY_OF_MONTH);

		calendar.setTimeInMillis(tm2);
		int y2 = calendar.get(Calendar.YEAR);
		int m2 = calendar.get(Calendar.MONTH);
		int d2 = calendar.get(Calendar.DAY_OF_MONTH);

		return (y1 == y2) && (m1 == m2) && (d1 == d2);
	}
	
	public static boolean isSameMouth(long time, long compTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(time);
		int timeYear = calendar.get(Calendar.YEAR);
		int timeMouth = calendar.get(Calendar.MONTH);

		calendar.setTimeInMillis(compTime);
		int compYear = calendar.get(Calendar.YEAR);
		int compMouth = calendar.get(Calendar.MONTH);
		if (timeYear == compYear) {
            return timeMouth == compMouth;
		}
		return false;
	}

}
